﻿using Microsoft.AspNetCore.SignalR;
using Microsoft.IdentityModel.JsonWebTokens;
using System.Security.Claims;

namespace B.Z.BasicData.API.Read.Service
{
    public class LoginSignalRHub : Hub
    {
        public override async Task OnConnectedAsync()
        {
            var userId = Context.User.FindFirstValue(JwtRegisteredClaimNames.Sub);

            await Clients.Caller.SendAsync(
                 "LoginSuccess",
                new
                {
                    Message = $"欢迎回来，{userId}！",
                    UserId = userId,
                    Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                });
            await base.OnConnectedAsync();
        }
    }
}
